﻿Imports System.IO

Public Class DefinitionMessage
    Inherits MessageBase

    Public Sub New(reader As BinaryReader)
        'First data byte is reserved
        Dim Reserved As Byte = reader.ReadByte()

        '2nd byte is the endianness
        Archetecture = If(reader.ReadByte = 0, ArchetectectureEnum.LittleEndian, ArchetectectureEnum.BigEndian)

        '3rd is the global message type
        GlobalMessageNumber = CType(reader.ReadUInt16, GlobalMessageNumberEnum)

        '4th is the number of fields
        FieldCount = reader.ReadByte

        'Read each field
        mFields = New List(Of FieldDefinition)
        For FieldIndex As Integer = 0 To FieldCount - 1
            Dim Field As New FieldDefinition
            Field.FieldDefinitionNumber = reader.ReadByte
            Field.Size = reader.ReadByte
            Field.BaseType = CType(reader.ReadByte, BaseTypeEnum)
            mFields.Add(Field)
        Next
    End Sub

    Public Property Archetecture As ArchetectectureEnum
    Public Property GlobalMessageNumber As GlobalMessageNumberEnum
    Public Property FieldCount As Byte

    Protected mFields As List(Of FieldDefinition)
    Public ReadOnly Property Fields As List(Of FieldDefinition)
        Get
            Return mFields
        End Get
    End Property

    Public Enum ArchetectectureEnum As Integer
        LittleEndian
        BigEndian
    End Enum
End Class
